
<!-- 新增和编辑弹窗 -->
<template>
  <a-modal
    :width="800"
    :visible="visible"
    title="详情"
    :body-style="{ paddingBottom: '8px' }"
    @update:visible="updateVisible"
    :footer="null"
  >
    <a-descriptions bordered :column="2" size="default">
      <a-descriptions-item label="设备ID">{{ form.recordId }}</a-descriptions-item>
      <a-descriptions-item label="主板ID">{{ form.mainId }}</a-descriptions-item>
      <a-descriptions-item label="推送类型">{{ formatType }}</a-descriptions-item>
      <a-descriptions-item label="推送情况">{{ formatSendResult }}</a-descriptions-item>
      <a-descriptions-item label="推送时间">{{ formatTime }}</a-descriptions-item>
    </a-descriptions>
    <a-divider/>
    <a-collapse :active-key="['1']">
      <a-collapse-panel key="1" header="具体参数">
        <p>{{ form.extend }}</p>
      </a-collapse-panel>
    </a-collapse>
  </a-modal>
</template>

<script>
import { reactive, toRefs, watchEffect } from 'vue';
import moment from 'moment';

export default {
  name: 'DeviceSpraymainboardCmdDetail',
  emits: ['update:visible'],
  props: {
    // 弹窗是否打开
    visible: Boolean,
    // 详情数据
    data: Object
  },
  setup(props, context) {
    const data = reactive({
      form: {}
    });

    const watch = watchEffect(() => {
      if (props.data) {
        data.form = Object.assign({}, props.data);
      }
    });

    const updateVisible = value => {
      context.emit('update:visible', value);
    };

    return {
      ...toRefs(data),
      watch,
      updateVisible
    };
  },
  computed : {
    formatType : function () {
      if (this.form.cmd == 161) {
        return "查询命令";
      } else if (this.form.cmd == 162) {
        return "修改强起温度";
      }  else {
        return '';
      }
    },
    formatSendResult : function() {
      if (this.form.isSend == 0) {
        return '未推送';
      } else if (this.form.isSend == 1) {
        return '推送中';
      } else if (this.form.isSend == 2) {
        return '已推送等反馈';
      } else if (this.form.isSend == 3) {
        return '推送且反馈';
      } else if (this.form.isSend == 4) {
        return '失败';
      } else {
        return '-';
      }
    },
    formatTime : function() {
      if (this.form.sendTime) {
        return moment(this.form.sendTime * 1000).format('YYYY-MM-DD HH:mm:ss')
      } else {
        return '-';
      }
    }
  }
};
</script>

<style scoped></style>

